package core.hxl;

import core.hxl.config.ScheduledTaskConfigurer;
import core.hxl.dynamicdatasource.DynamicDataSource;
import core.hxl.dynamicdatasource.DynamicDataSourceRegister;
import core.hxl.listener.TaskListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.sql.DataSource;

@SpringBootApplication
@EnableEurekaClient
@Import({DynamicDataSourceRegister.class})
@EnableTask
@EnableScheduling
public class TaskServerApp {

    public static void main(String[] args) {
        SpringApplication.run(TaskServerApp.class,args);
        Logger logger=LoggerFactory.getLogger(TaskServerApp.class);
        logger.info("----<<<<<task启动>>>>>----");
    }

    @Autowired
    private DataSource dataSource;

    @Bean
    public ScheduledTaskConfigurer getTaskConfigurer() {
        return new ScheduledTaskConfigurer(dataSource);
    }

    @Bean
    public TaskListener taskListener() {
        return new TaskListener();
    }

}
